package jjn.round1;

/**
 * @author Jiang Jining
 * @since 2023-05-28 21:15
 */
public class Interview17_11_FindClosest_Lcci {
    public int findClosest(String[] words, String word1, String word2) {
        int res = Integer.MAX_VALUE;
        int start1 = -1, start2 = -1;
        for (int i = 0; i < words.length; i++) {
            String word = words[i];
            if (word1.equals(word)) {
                start1 = i;
            }
            if (word2.equals(word)) {
                start2 = i;
            }
            if (start1 != -1 && start2 != -1) {
                res = Math.min(Math.abs(start1 - start2), res);
            }
        }
        return res;
    }
}
